﻿using AppCommerciaux.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AppCommerciaux.Views
{
    /// <summary>
    /// Logique d'interaction pour LigneCommandeEditView.xaml
    /// </summary>
    public partial class LigneCommandeEditView : UserControl
    {
        private LigneCommandeEditViewModel _viewModel;
        //public LigneCommandeEditViewModel()
        //{
        //    InitializeComponent();
        //}

        public LigneCommandeEditView(LigneCommandeEditViewModel ViewModel)
        {
            InitializeComponent();

            DataContext = _viewModel = ViewModel;

            //dataGridCommande.ItemsSource = _viewModel.ListCommande;
        }

        private string maintainsession;
        private void txtnumber_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (string.IsNullOrEmpty(((TextBox)sender).Text))
                maintainsession = "";
            else
            {
                double num = 0;
                bool success = double.TryParse(((TextBox)sender).Text, out num);
                if (success & num >= 0)
                {
                    ((TextBox)sender).Text.Trim();
                    maintainsession = ((TextBox)sender).Text;
                }
                else
                {
                    ((TextBox)sender).Text = maintainsession;
                    ((TextBox)sender).SelectionStart = ((TextBox)sender).Text.Length;
                }
            }
        }


    }
}
